package manager.listerner;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import com.rabbitmq.client.Channel;
import manager.goods.dao.SpuImageLogDao;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
@Component
public class DeleteImagesListerner {
        @Autowired
        private SpuImageLogDao spuImageLogDao;
        @Autowired
        private FastFileStorageClient storageClient;
        @RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = "crmshop.images.queen", durable = "true"),
        exchange = @Exchange(value = "crmshop.images.exchange",ignoreDeclarationExceptions = "true"),
        key = {"crmshop.images.delete"}))
        public void listenSms(List<Map<String,String>> message, Message msg, Channel channel) throws Exception {

                if (msg == null || msg.getBody().length <= 0) {
                    return;
                }
//                Example example=new Example(SpuImageLogVO.class);
//                List<String> spuIds=message.stream().map(item->item.get("spuId")).collect(Collectors.toList());
//                example.createCriteria().andIn("spuId",spuIds);
//                List<SpuImageLogVO> list=spuImageLogDao.selectByExample(example);
//                list.forEach(item->{
//                    String url=item.getImageUrl();
//                    if(url.startsWith("<p>")){
//                        url=url.substring(12,url.length()-5);
//                        storageClient.deleteFile(url);
//                    }else{
//                        storageClient.deleteFile(item.getImageUrl());
//                    }
//
//                });
        }
}
